package com.epfresh.activity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.epfresh.R;
import com.epfresh.api.entity.RequestEntityMap;
import com.epfresh.api.entity.ResponseEntity;
import com.epfresh.api.helper.ApplicationHelper;
import com.epfresh.api.http.OnRequestListener;
import com.epfresh.api.universalimageloader.core.ImageLoader;
import com.epfresh.api.universalimageloader.core.imageaware.ImageViewAware;
import com.epfresh.api.utils.L;
import com.epfresh.api.utils.LocalDisplay;
import com.epfresh.api.utils.T;
import com.epfresh.api.widget.MsgView;
import com.epfresh.api.widget.tablayout.utils.UnreadMsgUtils;
import com.epfresh.basedialog.ShareDialog;
import com.epfresh.bean.AddCarResponse;
import com.epfresh.bean.CountDownTime;
import com.epfresh.bean.Evaluate;
import com.epfresh.bean.GoodsDetail;
import com.epfresh.bean.StoreDetail;
import com.epfresh.bean.StoreGoodsPrice;
import com.epfresh.constant.Constant;
import com.epfresh.global.BaseActivity;
import com.epfresh.global.BaseApplication;
import com.epfresh.global.DataManager;
import com.epfresh.gradient.inter.GradientStyle;
import com.epfresh.gradient.utils.GradientUtils;
import com.epfresh.gradient.view.GradientActionBar;
import com.epfresh.gradient.view.GradientScrollView;
import com.epfresh.utils.TagsUtils;
import com.epfresh.views.BaseViewPager;
import com.epfresh.views.CountDownView;
import com.epfresh.views.CountDownView.*;
import com.epfresh.views.SlideDetailsLayout;
import com.epfresh.views.dialog.AddCartDialog;
import com.epfresh.views.dialog.BaseDialogView;
import com.epfresh.views.tag.FlowLayout;
import com.epfresh.views.tag.TagAdapter;
import com.epfresh.views.tag.TagFlowLayout;
import com.google.gson.Gson;
import com.umeng.analytics.MobclickAgent;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DetailGoodsActivity extends BaseActivity implements DataManager.OnCartCountChangeListener, OnCountDownListener {


    private TextView tvEvidence;
    //店铺休息按钮
    private TextView tvRest;
    //添加购物车
    private TextView tvAddCart;
    //添加购物车
    private View rlAddCart;
    //购物车
    private TextView tvCart;
    //购物车商品数量
    private MsgView msgCount;

    static final String TAG = "DetailGoodsActivity";
    private Context mContext;

    //private TextView address_flag;

    private TextView pull_flag;
    private TextView pull_flag_down;
    private TextView title;
//    @ViewInject(R.id.scrollView_image)
//    private ScrollView scrollView_image;

    private SlideDetailsLayout container; // 首页 动态广告
    private BaseViewPager viewpager_home; // 首页 动态广告
    ViewGroup group;
    private GradientScrollView scrollview; // 新浦开张
    private GradientActionBar actionbar;
    private TextView evaluate_more;
    private View toolbarLine;

    private TextView goods_detail_title;
    private TextView uint_price;
    private TextView uint_package;
    private TextView send_flag;
    private TextView number_tip;
    //private TextView name;

    private TextView tv_name;
    private TextView tv_package;

    /*预售现货，小车新样式*/
    private ImageView ivType;
    private TextView tvType;
    private TextView tv_type_tip;
    /*规格参数*/
    private View ll_1;
    private View ll_2;
    private TextView tv_key_1;
    private TextView tv_value_1;
    private TextView tv_value_2;
    private TextView tv_key_2;
    private TextView tv_key_3;
    private TextView tv_value_3;
    private TextView tv_key_4;
    private TextView tv_value_4;
    /*进场信息*/
    private View ll_in_all;
    private View tv_evidence;


    private View ll_produce_time;
    private View ll_produce_address;
    private View ll_weight;
    private View ll_top_market;
    private View ll_top_user;
    private View ll_in_time;

    private TextView tv_produce_time;
    private TextView tv_produce_address;
    private TextView tv_weight;
    private TextView tv_top_market;
    private TextView tv_top_user;
    private TextView tv_in_time;
    private TextView desc;

    private TextView commentsCount;
    private TextView goodCommentsRate;
    private LinearLayout evaluatell;
    private LinearLayout evaluatell1;
    private LinearLayout evaluatell2;
    private LinearLayout evaluatell3;
    //private RatingBar evaluate_bar1;
    private TextView evaluate_name1;
    private TextView evaluate_time1;
    private TextView evaluate_detail1;
    //private RatingBar evaluate_bar2;
    private TextView evaluate_name2;
    private TextView evaluate_time2;
    private TextView evaluate_detail2;
    //private RatingBar evaluate_bar3;
    private TextView evaluate_name3;
    private TextView evaluate_time3;
    private TextView evaluate_detail3;
    private LinearLayout ll_tags;


    private TextView tv_comment_state_1;
    private TextView tv_comment_state_2;
    private TextView tv_comment_state_3;

    private ImageView iv_comment_state_1;
    private ImageView iv_comment_state_2;
    private ImageView iv_comment_state_3;

    private WebView webView;
    private TextView order_start_text;
    private TextView order_start_info;
    private ImageView baseback;
    private ImageView ivShare;
    private ImageView ivCorner;
    String productId = "49";
    String promotionItemId = "";
    String storeId = "6";
    public static ArrayList<String> imagesList;//店铺介绍里的图片数组
    ArrayList<String> banners;
    String lastSnapshotId = "";
    String imageUrl;
    String titleStr;
    String description;

    int top = -1;

    GoodsDetail goodsDetail;
    RelativeLayout order_start;

    private TextView tvDownPayment;
    private TextView tvDeliveryTime;

    View rlDiscount;
    TextView tvDiscount, tvOriginalPrice;
    TextView tv_activity_second, tv_activity_promotion;

    private TextView tv_package_title;

    private TagFlowLayout comment_tags;
    private TagAdapter<GoodsDetail.CommentBean.GroupCountBean> commentTagAdapter;
    private List<GoodsDetail.CommentBean.GroupCountBean> commentTags = new ArrayList<>();
    private List<String> productTags = new ArrayList<>();
    private View ll_content;

    private int serviceStoreId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initViews();
        if (savedInstanceState != null) {
            String storeId = savedInstanceState.getString("storeId", "");
            String id = savedInstanceState.getString("id", "");
            String promotionItemId = savedInstanceState.getString("promotionItemId", "");
            String imageUrl = savedInstanceState.getString("image_url", "");
            String title = savedInstanceState.getString("title", "");
            if (id != null && !"".equals(id)) {
                getIntent().putExtra("storeId", storeId);
                getIntent().putExtra("id", id);
                getIntent().putExtra("image_url", imageUrl);
                getIntent().putExtra("title", title);
                getIntent().putExtra("promotionItemId", promotionItemId);
            }
        }

        mContext = this;
        int statusBarHeight = 0;
        if (Constant.isStatusBar) {
            int resId = getResources().getIdentifier("status_bar_height", "dimen", "android");
            if (resId > 0) {
                statusBarHeight = getResources().getDimensionPixelSize(resId);
            } else {
                statusBarHeight = LocalDisplay.SCREEN_HEIGHT_PIXELS / 25;
            }
            actionbar.setPadding(0, statusBarHeight, 0, 0);
        }
        ViewGroup.LayoutParams lp = actionbar.getLayoutParams();
        lp.height = getResources().getDimensionPixelSize(R.dimen.height_title);
        actionbar.setLayoutParams(lp);

        imagesList = new ArrayList<String>() {
        };
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 设置禁止横屏

        toolbarLine = findViewById(R.id.v_line);
        toolbarLine.setVisibility(View.INVISIBLE);
        new GradientUtils().setColorMode(GradientStyle.ASC, 0xfc, 0xfc, 0xfc)
                // 执行绑定
                .bind(actionbar, scrollview);
        baseback.setBackgroundDrawable(updateGradientDrawable(0x20));
        ivShare.setBackgroundDrawable(updateGradientDrawable(0x20));
        scrollview.setOnScrollChangedListener(new GradientScrollView.onScrollChangedListener() {
            @Override
            public void onScrollChanged(int l, int t, int oldl, int oldt, int totalHeight) {
                top = t;
                t = t > 0 ? t : 0;
                if (t > totalHeight) {//滑动顶部
                    toolbarLine.setVisibility(View.VISIBLE);
                    baseback.setBackgroundDrawable(updateGradientDrawable(0x0));
                    ivShare.setBackgroundDrawable(updateGradientDrawable(0x0));
                    title.setTextColor(Color.parseColor("#434343"));
                } else {
                    title.setTextColor(Color.parseColor("#ffffff"));
                    toolbarLine.setVisibility(View.INVISIBLE);
                    baseback.setBackgroundDrawable(updateGradientDrawable((totalHeight - t) * 0x20 / totalHeight));
                    ivShare.setBackgroundDrawable(updateGradientDrawable((totalHeight - t) * 0x20 / totalHeight));
                }

            }
        });
        group = (ViewGroup) findViewById(R.id.viewGroup);
        String scheme = getIntent().getScheme();

        if (scheme != null) {
            Uri data = getIntent().getData();
            String id = data.getQueryParameter("id");

            if (id != null && !"".equals(id)) {
                getIntent().putExtra("id", id);
            } else {
                startActivity(new Intent(this, HomeActivity.class));
                finish();
            }
        }
        if (getIntent().getStringExtra("id") != null) {
            storeId = getIntent().getStringExtra("storeId");
//            storeId = getIntent().getIntExtra("storeId",0)+"";
            productId = getIntent().getStringExtra("id");
            promotionItemId = getIntent().getStringExtra("promotionItemId");
            imageUrl = getIntent().getStringExtra("image_url");
            titleStr = getIntent().getStringExtra("title");
            serviceStoreId = getIntent().getIntExtra("serviceStoreId", -1);
        }
        container.setOnSlideDetailsListener(new SlideDetailsLayout.OnSlideDetailsListener() {
            @Override
            public void onStatucChanged(SlideDetailsLayout.Status status, boolean isFirstOpen) {
                if (status == SlideDetailsLayout.Status.OPEN) {
                    if (isFirstOpen) {
                    }
                    loadDetails();
                    title.setText(R.string.goods_pic_detail);
                    pull_flag.setVisibility(View.INVISIBLE);
                    pull_flag_down.setVisibility(View.VISIBLE);

                    actionbar.setGrade(0);
                } else {
                    title.setText(R.string.goods_detail);
                    pull_flag_down.setVisibility(View.INVISIBLE);
                    pull_flag.setVisibility(View.VISIBLE);
                    scrollview.setGradeWithHigh(top);
                }
            }
        });
        requestDetail();
        //  scrollview.setOnTouchListener(new TouchListenerImpl());
    }

    void initGoodsParameter() {

        tv_name = (TextView) findViewById(R.id.tv_name);
        tv_package_title = findViewById(R.id.tv_package_title);
        tv_package = (TextView) findViewById(R.id.tv_package);
        ivType = (ImageView) findViewById(R.id.iv_type);
        tvType = (TextView) findViewById(R.id.tv_type);
        ll_1 = findViewById(R.id.ll_1);
        ll_2 = findViewById(R.id.ll_2);
        tv_key_1 = (TextView) findViewById(R.id.tv_key_1);
        tv_value_1 = (TextView) findViewById(R.id.tv_value_1);
        tv_value_2 = (TextView) findViewById(R.id.tv_value_2);
        tv_key_2 = (TextView) findViewById(R.id.tv_key_2);
        tv_key_3 = (TextView) findViewById(R.id.tv_key_3);
        tv_value_3 = (TextView) findViewById(R.id.tv_value_3);
        tv_key_4 = (TextView) findViewById(R.id.tv_key_4);
        tv_value_4 = (TextView) findViewById(R.id.tv_value_4);
    }

    void initInInformation() {

        ll_in_all = findViewById(R.id.ll_in_all);
        tv_evidence = findViewById(R.id.tv_evidence);

        ll_produce_time = findViewById(R.id.ll_produce_time);
        ll_produce_address = findViewById(R.id.ll_produce_address);
        ll_weight = findViewById(R.id.ll_weight);
        ll_top_market = findViewById(R.id.ll_top_market);
        ll_top_user = findViewById(R.id.ll_top_user);
        ll_in_time = findViewById(R.id.ll_in_time);

        tv_produce_time = (TextView) findViewById(R.id.tv_produce_time);
        tv_produce_address = (TextView) findViewById(R.id.tv_produce_address);
        tv_weight = (TextView) findViewById(R.id.tv_weight);
        tv_top_market = (TextView) findViewById(R.id.tv_top_market);
        tv_top_user = (TextView) findViewById(R.id.tv_top_user);
        tv_in_time = (TextView) findViewById(R.id.tv_in_time);
    }

    void initViews() {
        setContentView(R.layout.activity_goodsdetail);
        initGoodsParameter();
        initInInformation();

        tvEvidence = (TextView) findViewById(R.id.tv_evidence);
        tvEvidence.setOnClickListener(this);
        findViewById(R.id.iv_close).setOnClickListener(this);
        tvDiscount = (TextView) findViewById(R.id.tv_discount);
        tvOriginalPrice = (TextView) findViewById(R.id.tv_original_price);

        rlDiscount = findViewById(R.id.rl_discount);

        tvDeliveryTime = (TextView) findViewById(R.id.tv_date);
        tvDownPayment = (TextView) findViewById(R.id.tv_handsel);

        tvRest = (TextView) findViewById(R.id.tv_rest);
        rlAddCart = findViewById(R.id.rl_cart);
        tvAddCart = (TextView) findViewById(R.id.tv_add_cart);

        msgCount = (MsgView) findViewById(R.id.msg);

        tvRest.setOnClickListener(this);
        rlAddCart.setOnClickListener(this);
        tvAddCart.setOnClickListener(this);

        ivCorner = (ImageView) findViewById(R.id.iv_corner);

        //address_flag = (TextView) findViewById(R.id.address_flag);
        pull_flag = (TextView) findViewById(R.id.pull_flag);
        pull_flag_down = (TextView) findViewById(R.id.pull_flag_down);
        title = (TextView) findViewById(R.id.basetitle);
        evaluate_more = (TextView) findViewById(R.id.evaluate_more);
        goods_detail_title = (TextView) findViewById(R.id.goods_detail_title);
        uint_price = (TextView) findViewById(R.id.uint_price);
        uint_package = (TextView) findViewById(R.id.uint_package);
        send_flag = (TextView) findViewById(R.id.send_flag);
        number_tip = (TextView) findViewById(R.id.number_tip);
        tv_type_tip = (TextView) findViewById(R.id.tv_type_tip);
        //name = (TextView) findViewById(R.id.name);
        tv_produce_time = (TextView) findViewById(R.id.tv_produce_time);
        tv_produce_address = (TextView) findViewById(R.id.tv_produce_address);
        tv_weight = (TextView) findViewById(R.id.tv_weight);
        tv_top_market = (TextView) findViewById(R.id.tv_top_market);
        tv_top_user = (TextView) findViewById(R.id.tv_top_user);
        tv_in_time = (TextView) findViewById(R.id.tv_in_time);
        desc = (TextView) findViewById(R.id.desc);
        commentsCount = (TextView) findViewById(R.id.commentsCount);
        goodCommentsRate = (TextView) findViewById(R.id.goodCommentsRate);
        goodCommentsRate.setOnClickListener(this);
        comment_tags = findViewById(R.id.comment_tags);
        commentTagAdapter = new TagAdapter<GoodsDetail.CommentBean.GroupCountBean>(commentTags) {
            @Override
            public View getView(FlowLayout parent, int position, GoodsDetail.CommentBean.GroupCountBean groupCountBean) {
                TextView commentTag = (TextView) LayoutInflater.from(DetailGoodsActivity.this).inflate(R.layout.item_comment_tag, parent, false);
                commentTag.setText(groupCountBean.getElement() + "(" + groupCountBean.getCnt() + ")");
                return commentTag;
            }
        };
        comment_tags.setAdapter(commentTagAdapter);
        ll_content = findViewById(R.id.ll_content);
        evaluate_name1 = (TextView) findViewById(R.id.evaluate_name1);
        evaluate_time1 = (TextView) findViewById(R.id.evaluate_time1);
        evaluate_detail1 = (TextView) findViewById(R.id.evaluate_detail1);
        evaluate_name2 = (TextView) findViewById(R.id.evaluate_name2);
        evaluate_time2 = (TextView) findViewById(R.id.evaluate_time2);
        evaluate_detail2 = (TextView) findViewById(R.id.evaluate_detail2);
        evaluate_name3 = (TextView) findViewById(R.id.evaluate_name3);
        evaluate_time3 = (TextView) findViewById(R.id.evaluate_time3);
        evaluate_detail3 = (TextView) findViewById(R.id.evaluate_detail3);

        order_start_text = (TextView) findViewById(R.id.order_start_text);
        order_start_info = (TextView) findViewById(R.id.order_start_info);

        container = (SlideDetailsLayout) findViewById(R.id.container);
        viewpager_home = (BaseViewPager) findViewById(R.id.viewpager_home);
        scrollview = (GradientScrollView) findViewById(R.id.scrollview_home);
        actionbar = (GradientActionBar) findViewById(R.id.actionbarLayoutId);
        ll_produce_time = (LinearLayout) findViewById(R.id.ll_produce_time);
        ll_produce_address = (LinearLayout) findViewById(R.id.ll_produce_address);
        ll_weight = (LinearLayout) findViewById(R.id.ll_weight);
        ll_top_market = (LinearLayout) findViewById(R.id.ll_top_market);
        ll_top_user = (LinearLayout) findViewById(R.id.ll_top_user);
        ll_in_time = (LinearLayout) findViewById(R.id.ll_in_time);
        evaluatell = (LinearLayout) findViewById(R.id.evaluatell);
        evaluatell1 = (LinearLayout) findViewById(R.id.evaluate_ll1);
        evaluatell2 = (LinearLayout) findViewById(R.id.evaluate_ll2);
        evaluatell3 = (LinearLayout) findViewById(R.id.evaluate_ll3);
/*        evaluate_bar1 = (RatingBar) findViewById(R.id.evaluate_bar1);
        evaluate_bar2 = (RatingBar) findViewById(R.id.evaluate_bar2);
        evaluate_bar3 = (RatingBar) findViewById(R.id.evaluate_bar3);*/

        tv_comment_state_1 = (TextView) findViewById(R.id.tv_comment_state_1);
        tv_comment_state_2 = (TextView) findViewById(R.id.tv_comment_state_2);
        tv_comment_state_3 = (TextView) findViewById(R.id.tv_comment_state_3);
        iv_comment_state_1 = (ImageView) findViewById(R.id.iv_comment_state_1);
        iv_comment_state_2 = (ImageView) findViewById(R.id.iv_comment_state_2);
        iv_comment_state_3 = (ImageView) findViewById(R.id.iv_comment_state_3);

        ll_tags = (LinearLayout) findViewById(R.id.ll_tags);

        tv_activity_second = (TextView) findViewById(R.id.tv_activity_second);
        tv_activity_promotion = (TextView) findViewById(R.id.tv_activity_promotion);

        webView = (WebView) findViewById(R.id.webview_detail);
        baseback = (ImageView) findViewById(R.id.baseback);
        ivShare = (ImageView) findViewById(R.id.iv_share);
        //@OnClick({R.id.baseback, R.id.order_start, R.id.evaluate_more, R.id.order_intoshop})
        evaluate_more.setOnClickListener(this);
        baseback.setOnClickListener(this);
        TextView order_intoshop = (TextView) findViewById(R.id.order_intoshop);
        order_intoshop.setOnClickListener(this);
        order_start = (RelativeLayout) findViewById(R.id.order_start);
        order_start.setOnClickListener(this);

        DataManager.getInstance().registerMsgView("detail_goods_activity", this);


        DataManager.getInstance().updateCartCnt();
    }

    @Override
    public void onCartCountChange(int count) {
        updateMsgCount(count);
    }

    private void updateMsgCount(int count) {
        if (count > 0) {
            msgCount.setVisibility(View.VISIBLE);
            UnreadMsgUtils.showLitter(msgCount, count, false);
        } else {
            msgCount.setVisibility(View.GONE);
        }
    }

    protected GradientDrawable updateGradientDrawable(int alpha) {
        GradientDrawable gd = new GradientDrawable();
        gd.setShape(GradientDrawable.OVAL);
        gd.setColor(Color.BLACK);
        gd.setAlpha(alpha);

        return gd;
    }

    @Override
    protected void onDestroy() {
        if (webView != null) {
            webView.destroy();
        }
        if (cdv != null) {
            cdv.finishTimer();
        }

        DataManager.getInstance().removeMsgView("detail_goods_activity");
        super.onDestroy();
    }

    @Override
    protected View getToolBar() {
        return null;
    }

    private String getHtmlImg() {
        StringBuilder sb = new StringBuilder();
        String htmlHead = "<html><head><style type=\"text/css\">body {margin:0px}</style><meta name=\"viewport\" content=\"width=device-width\"></head><body >";
        String htmlEnd = "</body></html>";
        sb.append(htmlHead);
        for (int i = 0; i < imagesList.size(); i++) {
            String url = imagesList.get(i);
            if (url != null & !"".equals(url)) {
                sb.append("<img src=\"");
                sb.append(url);
                sb.append("\" width = 100%/>");
            }
        }
        sb.append(htmlEnd);
        return sb.toString();
    }

    private void webViewSetting() {
        WebSettings ws = webView.getSettings();
//		ws.setUseWideViewPort(true);
        ws.setDefaultTextEncodingName("utf-8");
        ws.setLoadWithOverviewMode(true);
        ws.setJavaScriptEnabled(true);
        ws.setSupportZoom(true); // 设置可以支持缩放
        ws.setBuiltInZoomControls(false);
        ws.setLoadWithOverviewMode(true);
        ws.setPluginState(WebSettings.PluginState.ON);
        ws.setAllowFileAccess(true);
        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        ws.setDomStorageEnabled(true);
        ws.setCacheMode(WebSettings.LOAD_DEFAULT);
        // DisplayMetrics metrics = new DisplayMetrics();
        // getWindowManager().getDefaultDisplay().getMetrics(metrics);

    }

    boolean detailFlag = false;

    private class TouchListenerImpl implements View.OnTouchListener {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
                case MotionEvent.ACTION_DOWN:

                    break;
                case MotionEvent.ACTION_MOVE:
                    int scrollY = view.getScrollY();
                    int height = view.getHeight();
                    int scrollViewMeasuredHeight = scrollview.getChildAt(0).getMeasuredHeight();
                    if (scrollY == 0) {
                        System.out.println("滑动到了顶端 view.getScrollY()=" + scrollY);
                    }
                    if ((scrollY + height) == scrollViewMeasuredHeight) {
                        if (!detailFlag) {
                            detailFlag = true;
                            // initPics(response);
                            Log.i("imageflag", "开始展示新图片！");
                        }
                    }
                    break;
                default:
                    break;
            }
            return false;
        }
    }

    public void requestDetail() {
        final RequestEntityMap requestEntity = new RequestEntityMap();
        requestEntity.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_store_product_newLoad);
        requestEntity.putParameter("productSpecId", productId);
        if (serviceStoreId != -1) {
            requestEntity.putParameter("storeId", serviceStoreId);
        } else {
            requestEntity.putParameter("storeId", storeId);
        }
        if (promotionItemId != null && !"".equals(promotionItemId))
            requestEntity.putParameter("promotionItemId", promotionItemId);
        request(requestEntity, com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_store_product_newLoad, new OnRequestListener<GoodsDetail>() {
            @Override
            public GoodsDetail jsonToObj(String s) {
                Log.e("ESD", "获取的商品详情:" + s);
                return new Gson().fromJson(s, GoodsDetail.class);
            }

            @Override
            public void onFail(int i, Object o, Object o1) {
                showExceptionView(R.mipmap.order_no, o + "", 1);
            }

            @Override
            public void onResponseError(int i, Object o, Object o1) {
                showExceptionView(R.mipmap.order_no, o + "", 1);
            }

            @Override
            public void onStart(Object o) {
                showProgressView();
            }

            @Override
            public void onResponse(ResponseEntity<GoodsDetail> responseEntity, Object o) {

                String responseStr = responseEntity.getResponseStr();

                if (responseStr != null) {
                    GoodsDetail responseElement = responseEntity.getResponseElement();
                    goodsDetail = responseElement;
                    if (responseElement != null) {

                        showMainView();
                        goodsDetail = responseElement;
                        if (goodsDetail.isAcceptOrders()) {
                            tvAddCart.setVisibility(View.VISIBLE);
                            tvRest.setVisibility(View.GONE);
                        } else {
                            tvAddCart.setVisibility(View.GONE);
                            tvRest.setVisibility(View.VISIBLE);
                            View rl_delivery_info = findViewById(R.id.rl_delivery_info);
                            rl_delivery_info.setVisibility(View.GONE);
                        }
                        int type = goodsDetail.getProductParseDto().getType();

                        if (type == 2) {//预售,不能添加购物车
                            tvAddCart.setVisibility(View.GONE);
                            order_start.setVisibility(View.VISIBLE);
                        }

                        initModels(responseElement);
                        if (type == 1) {
                            initActivity(responseElement);
                        }
                        initPics(responseElement);
                        initEvaluates(responseElement);
                        Log.e("getPromotionItemType", "" + responseElement.getPromotionItemType());

                        String promotionMarkUrl = "";
                        if (responseElement.getPromotion() != null) {
                            promotionMarkUrl = responseElement.getPromotion().getTagImageUrl();
                        }
                        if (promotionMarkUrl != null && !"".equals(promotionMarkUrl))
                            ImageLoader.getInstance().displayImage(promotionMarkUrl, new ImageViewAware(ivCorner), BaseApplication.getTagOptions(promotionMarkUrl), null, null, null);


                        return;
                    }
                }

                showExceptionView(R.mipmap.order_no, "获取数据错误", 1);
                T.toast("数据加载失败,请重试");
            }
        });
    }


    void initActivity(GoodsDetail responseElement) {
        tvOriginalPrice.setVisibility(View.VISIBLE);
        if (responseElement.getPromotion() != null && responseElement.getPromotion().getType() == 1) {//促销
            View rl_promotion = findViewById(R.id.rl_promotion);
            TextView tv_promotion_hint = (TextView) findViewById(R.id.tv_promotion_hint);
            TextView tv_day_number_1 = (TextView) findViewById(R.id.tv_day_number_1);
            TextView tv_day_number_2 = (TextView) findViewById(R.id.tv_day_number_2);
            View tv_promotion_day = findViewById(R.id.tv_promotion_day);
            TextView tv_promotion_limit = (TextView) findViewById(R.id.tv_promotion_limit);
            rl_promotion.setVisibility(View.VISIBLE);
            if (responseElement.getPromotion().getQuantityPerAccount() == null) {
                tv_promotion_limit.setVisibility(View.INVISIBLE);
            } else
                tv_promotion_limit.setText("限购" + responseElement.getPromotion().getQuantityPerAccount() + responseElement.getUnit());
            if (responseElement.getPromotion().getStatus() == 1) { // WAITING(1, "不可购买"), UNDERWAY(2, "可购买"), OVER(3, "结束了"), SELL_OUT(4, "抢光了");
                tvAddCart.setVisibility(View.GONE);
                tvRest.setText("即将开始");
                tvRest.setVisibility(View.VISIBLE);
            } else if (responseElement.getPromotion().getStatus() == 3) {
                tv_promotion_hint.setText("结束了");
                tvAddCart.setVisibility(View.GONE);
                tvRest.setText("结束了");
                tvRest.setVisibility(View.VISIBLE);
            } else if (responseElement.getPromotion().getStatus() == 4) {
                tv_promotion_hint.setText("抢光了");
                tvAddCart.setVisibility(View.GONE);
                tvRest.setText("抢光了");
                tvRest.setVisibility(View.VISIBLE);
            } else if (responseElement.getPromotion().getStatus() == 2) {
                tv_promotion_hint.setText("距结束");
                tv_promotion_day.setVisibility(View.VISIBLE);
                rl_promotion.setBackgroundColor(Color.parseColor("#70CCAD"));
                //rl_promotion.getBackground().setAlpha(100);
                try {
                    Date now = new Date();
                    String flag = responseElement.getPromotion().getEndTime();
                    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                    java.util.Date date = formatter.parse(flag);
                    long s1 = date.getTime();//将时间转为毫秒
                    long s2 = System.currentTimeMillis();//得到当前的毫秒

                    long day = (s1 - s2) / 86400000 /*+ ((s1-s2)%86400000>0?1:0)*/;
                    //System.out.println("距现在已有"+day+"天，你得抓紧时间学习了" );

                    /*
                    Date end = formatter.parse(flag);
                    Calendar aCalendar = Calendar.getInstance();
                    aCalendar.setTime(now);
                    int day1 = aCalendar.get(Calendar.DAY_OF_YEAR);
                    aCalendar.setTime(end);
                    int day2 = aCalendar.get(Calendar.DAY_OF_YEAR);
                    int number = day2-day1;*/
                    tv_day_number_1.setVisibility(View.VISIBLE);
                    tv_day_number_2.setVisibility(View.VISIBLE);
                    if (day > 10) {
                        tv_day_number_1.setText("" + day / 10);
                        tv_day_number_2.setText("" + day % 10);
                    } else {
                        tv_day_number_1.setText("0");
                        tv_day_number_2.setText("" + day);
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        } else if (responseElement.getPromotion() != null && responseElement.getPromotion().getType() == 2) {//秒杀
            View rl_seconds = findViewById(R.id.rl_seconds);
            rl_seconds.setVisibility(View.VISIBLE);
            TextView tv_second_hint = (TextView) findViewById(R.id.tv_second_hint);
            TextView tv_second_limit = (TextView) findViewById(R.id.tv_second_limit);
            if (responseElement.getPromotion().getQuantityPerAccount() == null) {
                tv_second_limit.setVisibility(View.INVISIBLE);
            } else
                tv_second_limit.setText("限购" + responseElement.getPromotion().getQuantityPerAccount() + responseElement.getUnit());
            if (responseElement.getPromotion().getStatus() == 1) { // WAITING(1, "不可购买"), UNDERWAY(2, "可购买"), OVER(3, "结束了"), SELL_OUT(4, "抢光了");
                tvAddCart.setVisibility(View.GONE);
                tvRest.setText("即将开始");
                tvRest.setVisibility(View.VISIBLE);
                initCdv();
            } else if (responseElement.getPromotion().getStatus() == 2) {
                initCdv();
                rl_seconds.setBackgroundColor(Color.parseColor("#70CCAD"));
                GradientDrawable myGrad = (GradientDrawable) tv_second_hint.getBackground();
                myGrad.setColor(Color.parseColor("#4CB18E"));
            } else if (responseElement.getPromotion().getStatus() == 3) {
                tvAddCart.setVisibility(View.GONE);
                tvRest.setText("结束了");
                tvRest.setVisibility(View.VISIBLE);
                tv_second_hint.setText("来晚了，已结束");
                GradientDrawable myGrad = (GradientDrawable) tv_second_hint.getBackground();
                myGrad.setColor(Color.parseColor("#999999"));
                rl_seconds.setBackgroundColor(Color.parseColor("#888888"));
                rl_seconds.getBackground().setAlpha(100);

            } else if (responseElement.getPromotion().getStatus() == 4) {
                tv_second_hint.setText("来晚了，已抢光");
                tvAddCart.setVisibility(View.GONE);
                tvRest.setText("抢光了");
                tvRest.setVisibility(View.VISIBLE);
                if (cdv == null)
                    cdv = (CountDownView) findViewById(R.id.cdv);
                cdv.setTitle("抢光了");
                tv_second_hint.setText("来晚了，已抢光");
                GradientDrawable myGrad = (GradientDrawable) tv_second_hint.getBackground();
                myGrad.setColor(Color.parseColor("#999999"));
            }
        } else {
            tvOriginalPrice.setVisibility(View.GONE);
            if (goodsDetail.isAcceptOrders()) {
                tvAddCart.setVisibility(View.VISIBLE);
                tvRest.setVisibility(View.GONE);
            } else {
                tvAddCart.setVisibility(View.GONE);
                tvRest.setText("暂不接单");
                tvRest.setVisibility(View.VISIBLE);
            }
        }
    }

    CountDownTime cdt;
    CountDownView cdv;
    String beginTime, endTime, sysDate;

    void initCdv() {
        beginTime = goodsDetail.getPromotion().getBeginTime();
        endTime = goodsDetail.getPromotion().getEndTime();
        sysDate = goodsDetail.getResponseTime();
        cdt = new CountDownTime();
        cdv = (CountDownView) findViewById(R.id.cdv);
        cdv.setOnCountDownListener(this);
        cdt.setStartSubTime(beginTime);//fineRecommendation.getString("beginTime"));
        cdt.setEndSubTime(endTime);//fineRecommendation.getString("endTime"));
        cdt.setSysDate(sysDate);//fineRecommendation.getString("sysDate"));
        Log.e("cdt", "s:" + cdt.getStartSubTime());
        Log.e("cdt", "l:" + cdt.getSysDate());
        Log.e("cdt", "e:" + cdt.getEndSubTime());
        cdt.init();
        long countDownTime = cdt.getCountDownTime();
        if (countDownTime == 0) {//活动已经结束
//                cdv.setVisibility(View.INVISIBLE);
        } else if (countDownTime > 0) {//活动进行中
            cdv.setVisibility(View.VISIBLE);
            cdv.showTimer(cdt, countDownTime, 1000);
        } else if (countDownTime < 0) {
            cdv.setVisibility(View.VISIBLE);
            cdv.showTimer(cdt, countDownTime, 1000);
        }
    }


    public void initNewParameters(GoodsDetail response) {
        String html = "<font color=\"#00ffffff\">预售 </font>";
        //vh.tv_title.setText(Html.fromHtml(html));
        if (response.getProductParseDto().getType() == 2) {
            //aaaaa
            ivType.setImageResource(R.mipmap.goods_type_pre);
            tvType.setText("预售");
            tvType.setTextColor(Color.parseColor("#40acea"));
            tv_type_tip.setVisibility(View.VISIBLE);
            //tv_type_tip.setText("预计" + response.getDeliveryTime().substring(0, 10) + "到货");
            tv_type_tip.setText(Html.fromHtml(html + "最晚下单时间" + response.getSaleDeadline() + "，下单后预计" + response.getArrivalDate() + "送达"));
            goods_detail_title.setText(Html.fromHtml("<font color=\"#40acea\">【预售】 </font>" + response.getProductParseDto().getTitle()));

        } else {
            ivType.setImageResource(R.mipmap.goods_type_now);
            tvType.setText("现货");
            tvType.setTextColor(Color.parseColor("#F21000"));
            goods_detail_title.setText(response.getProductParseDto().getTitle());
            tv_type_tip.setVisibility(View.VISIBLE);
            //tv_type_tip.setText("已于" + response.getPluckingTime() + "进场");
            tv_type_tip.setText(Html.fromHtml(html + response.getSaleDeadline() + "前下单，可选择" + response.getArrivalDate() + "送达"));
        }

        if (response.getPurchase() == null) {
            ll_in_all.setVisibility(View.GONE);
            findViewById(R.id.ll_in_information).setVisibility(View.GONE);
        } else {
            GoodsDetail.Purchase purchase = response.getPurchase();
            if (purchase.getOriginProveImages() == null || purchase.getOriginProveImages().size() == 0) {
                tv_evidence.setVisibility(View.GONE);
            } else {

                loadEvidences(purchase);

            }
            if (purchase.getProductionDate() != null && !"".equals(purchase.getProductionDate()) && !"null".equals(purchase.getProductionDate())) {
                tv_produce_time.setText(purchase.getProductionDate().toString());
            } else {
                ll_produce_time.setVisibility(View.GONE);
            }
            if (purchase.getOrigin() != null && !"".equals(purchase.getOrigin()) && !"null".equals(purchase.getOrigin())) {
                tv_produce_address.setText(purchase.getOrigin());
            } else {
                ll_produce_address.setVisibility(View.GONE);
            }
            if (purchase.getUpstreamMarket() != null && !"".equals(purchase.getUpstreamMarket()) && !"null".equals(purchase.getUpstreamMarket())) {
                tv_top_market.setText(purchase.getUpstreamMarket());
            } else {
                ll_top_market.setVisibility(View.GONE);
            }
            if (purchase.getUpstreamMerchant() != null && !"".equals(purchase.getUpstreamMerchant()) && !"null".equals(purchase.getUpstreamMerchant())) {
                tv_top_user.setText(purchase.getUpstreamMerchant());
            } else {
                ll_top_user.setVisibility(View.GONE);
            }
            if (purchase.getQuantity() != null && !"".equals(purchase.getQuantity()) && !"null".equals(purchase.getQuantity())) {
                tv_weight.setText(purchase.getQuantity() + response.getUnit());
            } else {
                ll_weight.setVisibility(View.GONE);
            }
            if (purchase.getArrivalDate() != null && !"".equals(purchase.getArrivalDate()) && !"null".equals(purchase.getArrivalDate())) {
                tv_in_time.setText(purchase.getArrivalDate().toString());
            } else {
                ll_in_time.setVisibility(View.GONE);
            }
        }


        ArrayList<String> key = new ArrayList<>();
        ArrayList<String> value = new ArrayList<>();


        tv_name.setText(response.getCategoryiiiName());
//        if(response.getSpecies()!=null&&!"".equals(response.getSpecies())&&!"null".equals(response.getSpecies())){
//            tv_name.setText(response.getSpecies());
//        }
        if (response.getPack().equals("") || response.getPack() == null) {
            tv_package.setVisibility(View.INVISIBLE);
            tv_package_title.setVisibility(View.INVISIBLE);
        } else {
            if (response.getName() == null || response.getName().equals("默认")) {
                tv_package.setText(response.getPack());
            } else {
                tv_package.setText(response.getName() + "(" + response.getPack() + ")");
            }

        }
//        if(response.getVariety()!=null&&!"".equals(response.getVariety())&&!"null".equals(response.getVariety())){
//            key.add("品种：");
//            value.add(response.getVariety());
//        }
//        if(response.getLevel()!=null&&!"".equals(response.getLevel())&&!"null".equals(response.getLevel())){
//            key.add("等级：");
//            value.add(response.getLevel());
//        }
//        if(response.getOrigin()!=null&&!"".equals(response.getOrigin())&&!"null".equals(response.getOrigin())){
//            key.add("产地：");
//            value.add(response.getOrigin());
//        }
//        if(response.getBrand()!=null&&!"".equals(response.getBrand())&&!"null".equals(response.getBrand())){
//            key.add("品牌：");
//            value.add(response.getBrand());
//        }
        if (key.size() == 0) {
            ll_1.setVisibility(View.GONE);
            ll_2.setVisibility(View.GONE);
        } else if (key.size() == 1) {
            ll_2.setVisibility(View.GONE);
            ll_1.setVisibility(View.VISIBLE);
            tv_key_1.setHint(key.get(0));
            tv_value_1.setText(value.get(0));
            tv_key_1.setVisibility(View.VISIBLE);
            tv_value_1.setVisibility(View.VISIBLE);
        } else if (key.size() == 2) {
            ll_2.setVisibility(View.GONE);
            ll_1.setVisibility(View.VISIBLE);
            tv_key_1.setHint(key.get(0));
            tv_value_1.setText(value.get(0));
            tv_key_2.setHint(key.get(1));
            tv_value_2.setText(value.get(1));
            tv_key_1.setVisibility(View.VISIBLE);
            tv_value_1.setVisibility(View.VISIBLE);
            tv_key_2.setVisibility(View.VISIBLE);
            tv_value_2.setVisibility(View.VISIBLE);
        } else if (key.size() == 3) {
            ll_2.setVisibility(View.VISIBLE);
            ll_1.setVisibility(View.VISIBLE);
            tv_key_1.setHint(key.get(0));
            tv_value_1.setText(value.get(0));
            tv_key_2.setHint(key.get(1));
            tv_value_2.setText(value.get(1));
            tv_key_3.setHint(key.get(2));
            tv_value_3.setText(value.get(2));
            tv_key_1.setVisibility(View.VISIBLE);
            tv_value_1.setVisibility(View.VISIBLE);
            tv_key_2.setVisibility(View.VISIBLE);
            tv_value_2.setVisibility(View.VISIBLE);
            tv_key_3.setVisibility(View.VISIBLE);
            tv_value_3.setVisibility(View.VISIBLE);
        } else {
            ll_2.setVisibility(View.VISIBLE);
            ll_1.setVisibility(View.VISIBLE);
            tv_key_1.setHint(key.get(0));
            tv_value_1.setText(value.get(0));
            tv_key_2.setHint(key.get(1));
            tv_value_2.setText(value.get(1));
            tv_key_3.setHint(key.get(2));
            tv_value_3.setText(value.get(2));
            tv_key_4.setHint(key.get(3));
            tv_value_4.setText(value.get(3));
            tv_key_1.setVisibility(View.VISIBLE);
            tv_value_1.setVisibility(View.VISIBLE);
            tv_key_2.setVisibility(View.VISIBLE);
            tv_value_2.setVisibility(View.VISIBLE);
            tv_key_3.setVisibility(View.VISIBLE);
            tv_value_3.setVisibility(View.VISIBLE);
            tv_key_4.setVisibility(View.VISIBLE);
            tv_value_4.setVisibility(View.VISIBLE);
        }


    }

    @SuppressLint("SetTextI18n")
    public void initModels(GoodsDetail response) {
        initNewParameters(response);
        //address_flag.setText("在" + response.getCityName() + "销售");sadas
        if (response.getOriginalPrice() != null && !"".equals(response.getOriginalPrice()) && !"null".equals(response.getOriginalPrice())) {
            //tvDiscount.setText(""+response.getDiscountRate()+"折");
            tvOriginalPrice.setText("原价：" + response.getOriginalPrice() + "元/" + response.getUnit());
            tvOriginalPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
            tvOriginalPrice.setVisibility(View.VISIBLE);
            //rlDiscount.setVisibility(View.VISIBLE);
        } else {
            tvOriginalPrice.setVisibility(View.GONE);
        }

        if (response.getProductParseDto().getType() == 2) {//预售商品
            tvOriginalPrice.setVisibility(View.GONE);
        }
        tvDownPayment.setText(response.getDepositStr() + response.getDeposit() + "元/" + response.getChargeUnit());
        tvDeliveryTime.setText("预计送达时间" + response.getDeliveryTime());
        storeId = response.getStoreId() + "";
        titleStr = response.getTitle();
        uint_package.setText(response.getPack());
        if (null != response.getProductSpecPrice()) {
            if (response.getProductSpecPrice().isPrePrice()) {
                uint_price.setText(response.getPrice() + "元/" + response.getChargeUnit());
            } else {
                uint_price.setText("时价");
                tvOriginalPrice.setVisibility(View.GONE);
            }
        }
        if (response.getLowStockTip() != null && !response.getLowStockTip().equals("")) {
            number_tip.setVisibility(View.VISIBLE);
            number_tip.setText(response.getLowStockTip());
        } else {
            number_tip.setVisibility(View.GONE);
        }
        description = response.getProductParseDto().getDescription();
        if (description != null && !description.equals("null"))
            desc.setText(description);
        commentsCount.setText("全部评价(" + response.getComment().getCommentsCount() + ")");
        goodCommentsRate.setText("满意度" + response.getComment().getGoodCommentsRate() + "%");
        commentTags.clear();
        for (int i = 0; i < response.getComment().getGroupCount().size(); i++) {
            if (i < 3) {
                commentTags.add(response.getComment().getGroupCount().get(i));
            }
        }
        commentTagAdapter.notifyDataChanged();
        send_flag.setText(response.getLeastCount());

        lastSnapshotId = response.getLastSnapshotId();
        hideEmpty(response);
        if (response.getPromotion() != null && response.getPromotion().getType() == 1) {
            tv_activity_promotion.setVisibility(View.VISIBLE);
            tv_activity_second.setVisibility(View.GONE);
        } else if (response.getPromotion() != null && response.getPromotion().getType() == 2) {
            tv_activity_second.setVisibility(View.VISIBLE);
            tv_activity_promotion.setVisibility(View.GONE);
        } else {
            tv_activity_second.setVisibility(View.GONE);
            tv_activity_promotion.setVisibility(View.GONE);
        }
        if (response.getTags() != null && response.getTags().size() > 0) {
            Log.e("tags", "" + response.getTags().size());
            ll_tags.setVisibility(View.VISIBLE);
            TagsUtils.initTags(ll_tags, response.getTags());
        } else {
            ll_tags.setVisibility(View.GONE);
        }
    }

    private void hideEmpty(GoodsDetail response) {
        if (TextUtils.isEmpty(response.getName()) || response.getName().equals("null")) {
            View llName = findViewById(R.id.ll_name);
            llName.setVisibility(View.GONE);
        }
    }

    public void initPics(GoodsDetail response) {
        imagesList = (ArrayList) response.getImgList();
        if (imagesList == null || imagesList.size() <= 0) {
            pull_flag.setVisibility(View.INVISIBLE);
            container.setIsOnlyFront(true);
        }
        banners = (ArrayList) response.getBanner();
        if (banners == null || banners.size() == 0) {
            return;
        }
        if (banners.size() == 1) {
            ImageView imageView = (ImageView) findViewById(R.id.iv_only_one);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            ImageLoader.getInstance().displayImage(banners.get(0), imageView);

            imageView.setVisibility(View.VISIBLE);
            return;
        }
        setViewpagerAdapter();


    }


    private void loadEvidences(GoodsDetail.Purchase purchase) {
        LinearLayout ll_evidences = (LinearLayout) findViewById(R.id.ll_evidences);
        ImageView images[] = new ImageView[purchase.getOriginProveImages().size()];
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        ll_evidences.removeAllViews();
        for (int i = 0; i < purchase.getOriginProveImages().size(); i++) {
            images[i] = new ImageView(this);
            images[i].setScaleType(ImageView.ScaleType.FIT_CENTER);
            images[i].setAdjustViewBounds(true);
            layoutParams.setMargins(0, 0, 0, 15);
            images[i].setLayoutParams(layoutParams);
            ll_evidences.addView(images[i], ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            ImageLoader.getInstance().displayImage(purchase.getOriginProveImages().get(i), images[i]);
        }
    }

    private void loadDetails() {
        if (imagesList == null || imagesList.size() <= 0) {
            pull_flag.setVisibility(View.INVISIBLE);
//            container.mCurrentViewIndex=1;
        } else {
//            container.setImage(image_ll, imagesList, bitmapUtils);
            webViewSetting();
            webView.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    //返回值是true的时候控制去WebView打开，为false调用系统浏览器或第三方浏览器
//                    view.loadUrl(url);
                    return true;
                }
            });

            webView.loadDataWithBaseURL(null, getHtmlImg(), "text/html", "UTF-8", null);

//            ImageView images[] = new ImageView[imagesList.size()];
//            for (int i = 0; i < imagesList.size(); i++) {
//                images[i] = new ImageView(this);
//                images[i].setScaleType(ImageView.ScaleType.FIT_CENTER);
//                images[i].setAdjustViewBounds(true);
//                image_ll.addView(images[i], ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//                ImageLoader.getInstance().displayImage(imagesList.get(i), images[i]);
////                bitmapUtils.display(images[i], imagesList.get(i));
//            }
        }
    }

    public void initEvaluates(GoodsDetail response) {
        ViewGroup view = (ViewGroup) findViewById(R.id.ll_child);
        List<GoodsDetail.CommentBean.CommentsBean> comments = response.getComment().getComments();
//        ArrayList<Evaluate> evaluates = (ArrayList) response.getComments();
        if (response.getComment().getCommentsCount() == 0) {
//            evaluatell.setVisibility(View.GONE);
            ll_content.setVisibility(View.GONE);
            goodCommentsRate.setVisibility(View.GONE);
            commentsCount.setText("暂无商品评价");
            return;
        }
        if (comments.size() > 0) {
            addComment(view, comments.get(0));
        } else {
            return;
        }
        if (comments.size() > 1) {
            addComment(view, comments.get(1));
        } else {
            return;
        }
        if (comments.size() > 2) {
            addComment(view, comments.get(2));
        } else {
            return;
        }
        if (response.getCommentsCount() > 3) {
            evaluate_more.setVisibility(View.VISIBLE);
        } else {
            return;
        }
        return;
    }

    void addComment(ViewGroup parent, GoodsDetail.CommentBean.CommentsBean bean) {
        ImageView iv_1, iv_2, iv_3;
        TextView txt_account_name, tv_comment_state, tv_comment_time, tv_comment_detail, txt_product_name;
        ImageView iv_comment_state;
        TagFlowLayout product_tags;
        TagAdapter<String> productTagAdapter = new TagAdapter<String>(productTags) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView productTag = (TextView) LayoutInflater.from(DetailGoodsActivity.this).inflate(R.layout.item_product_tag, parent, false);
                productTag.setText(s);
                return productTag;
            }
        };
        View child = inflaterView(R.layout.include_evaluate_item, null);
        parent.addView(child);
        txt_account_name = child.findViewById(R.id.txt_account_name);
        tv_comment_state = child.findViewById(R.id.tv_comment_state);
        tv_comment_time = child.findViewById(R.id.tv_comment_time);
        iv_comment_state = child.findViewById(R.id.iv_comment_state);
        tv_comment_detail = child.findViewById(R.id.tv_comment_detail);
        product_tags = child.findViewById(R.id.product_tags);
        txt_product_name = child.findViewById(R.id.txt_product_name);
        product_tags.setAdapter(productTagAdapter);
        initCommentView(tv_comment_state, iv_comment_state, bean.getScore());
        if (!TextUtils.isEmpty(bean.getAccountName()))
            txt_account_name.setText(bean.getAccountName().substring(0, 1) + "**");
        tv_comment_detail.setText(bean.getContent());
        tv_comment_time.setText(bean.getTime());
        if (!TextUtils.isEmpty(bean.getProductTitle()) && !TextUtils.isEmpty(bean.getChargeUnit())) {
            txt_product_name.setText(bean.getProductTitle() + bean.getProductCount() + bean.getChargeUnit());
        }

        productTags.clear();
        productTags.addAll(bean.getFastMessage());
        productTagAdapter.notifyDataChanged();

        if (bean.getAttachmentUrls() == null || bean.getAttachmentUrls().size() == 0) {
            child.findViewById(R.id.ll_image).setVisibility(View.GONE);
        } else {
            child.findViewById(R.id.ll_image).setVisibility(View.VISIBLE);

            switch (bean.getAttachmentUrls().size()) {
                case 1:
                    iv_1 = child.findViewById(R.id.iv_1);
                    iv_1.setVisibility(View.VISIBLE);
                    ImageLoader.getInstance().displayImage(bean.getAttachmentUrls().get(0), new ImageViewAware(iv_1));
                    break;
                case 2:
                    iv_1 = child.findViewById(R.id.iv_1);
                    iv_2 = child.findViewById(R.id.iv_2);
                    iv_1.setVisibility(View.VISIBLE);
                    iv_2.setVisibility(View.VISIBLE);
                    ImageLoader.getInstance().displayImage(bean.getAttachmentUrls().get(0), new ImageViewAware(iv_1));
                    ImageLoader.getInstance().displayImage(bean.getAttachmentUrls().get(1), new ImageViewAware(iv_2));
                    break;
                case 3:
                    iv_1 = child.findViewById(R.id.iv_1);
                    iv_2 = child.findViewById(R.id.iv_2);
                    iv_3 = child.findViewById(R.id.iv_3);
                    iv_1.setVisibility(View.VISIBLE);
                    iv_2.setVisibility(View.VISIBLE);
                    iv_3.setVisibility(View.VISIBLE);
                    ImageLoader.getInstance().displayImage(bean.getAttachmentUrls().get(0), new ImageViewAware(iv_1));
                    ImageLoader.getInstance().displayImage(bean.getAttachmentUrls().get(1), new ImageViewAware(iv_2));
                    ImageLoader.getInstance().displayImage(bean.getAttachmentUrls().get(2), new ImageViewAware(iv_3));
                    break;
            }
        }
    }


    String[] comments = {"吐槽", "满意", "点赞"};
    String[] commentColors = {"#626262", "#ff9600", "#f14c2f"};
    int[] commentImages = {R.mipmap.icon_tu_cao, R.mipmap.icon_man_yi, R.mipmap.icon_dian_zan};

    private void initCommentView(TextView tv, ImageView iv, int score) {
        if (score > 0 && score < 4) {
            tv.setText(comments[score - 1]);
            tv.setTextColor(Color.parseColor(commentColors[score - 1]));
            iv.setImageResource(commentImages[score - 1]);
        }
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_close:
                findViewById(R.id.rl_evidence).setVisibility(View.GONE);
                break;
            case R.id.tv_evidence:
                findViewById(R.id.rl_evidence).setVisibility(View.VISIBLE);
                break;
            case R.id.baseback:
                finish();
                break;
            case R.id.iv_share:
                share();
                break;
            case R.id.order_start:
                addCart();
                break;
            case R.id.order_intoshop:
                if (goodsDetail.isDc()) {
                    request();
                    return;
                }
                Intent store = new Intent(mContext, CommonStoreActivity.class);
                store.putExtra("storeId", storeId);
                startActivity(store);
                break;
            case R.id.evaluate_more:
                Intent more = new Intent(mContext, MoreEvaluateActivity.class);
                more.putExtra("productId", productId);
                if (goodsDetail != null && goodsDetail.getGoodCommentsRate() != null && goodsDetail.getGoodCommentsRate().length() > 1) {
                    String rate = goodsDetail.getGoodCommentsRate().substring(0, goodsDetail.getGoodCommentsRate().length() - 1);
                    more.putExtra("evaluate_percent", rate);
                } else
                    more.putExtra("evaluate_percent", "0");
                startActivity(more);
                break;
            case R.id.tv_add_cart:
                addCart();
                break;
            case R.id.rl_cart:
                cart();
                break;
            case R.id.tv_rest:
                rest();
                break;
            case R.id.goodCommentsRate:
                Intent h5Intent = new Intent(DetailGoodsActivity.this, WebActivity.class);
                h5Intent.putExtra(Constant.KEY_WEB_URL, com.epfresh.api.constant.Constant.URL_GOODS_DETAIL_COMMENT + "productSpecId=" + productId);
                h5Intent.putExtra(Constant.KEY_WEB_TITLE, "评价");
                startActivity(h5Intent);
                break;
            default:
                break;
        }
    }


    /*-----------------------------------Viewpager循环翻页----------------------------------------------------------------*/
    private static final int MSG_CHANGE_PHOTO = 1;

    /**
     * 图片自动切换时间
     */
    private static final int PHOTO_CHANGE_TIME = 5000;
    ImageView[] imageFlag;

    private boolean isfirst = true;
    /**
     * 图片资源id
     */
    private int[] imgIdArray;
    /**
     * 装ImageView数组
     */
    private ImageView[][] mImageViews;

    /**
     * 装点点的ImageView数组
     */
    private ImageView[] tips;
    private Handler mHandler = new Handler() {
        @Override
        public void dispatchMessage(Message msg) {
            switch (msg.what) {
                case MSG_CHANGE_PHOTO:
                    int index = viewpager_home.getCurrentItem();
                    viewpager_home.setCurrentItem(index + 1);
                    mHandler.sendEmptyMessageDelayed(MSG_CHANGE_PHOTO,
                            PHOTO_CHANGE_TIME);
                    break;
            }
            super.dispatchMessage(msg);
        }
    };

    private void setViewpagerAdapter() {
        getViewpagerdate();
        viewpager_home.setAdapter(new MyAdapter());
        viewpager_home.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                if (banners.size() == 0 || banners.size() == 1)
                    return false;
                else
                    return false;
            }
        });
        // 设置ViewPager的默认项, 设置为长度的50倍，这样子开始就能往左滑动
        viewpager_home.setCurrentItem((banners.size()) * 50);
        if (banners.size() > 1) {
            if (isfirst) {
                mHandler.sendEmptyMessageDelayed(MSG_CHANGE_PHOTO,
                        PHOTO_CHANGE_TIME);
                isfirst = false;
            }

        }
        viewpager_home.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageScrollStateChanged(int arg0) {

            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {

            }

            @Override
            public void onPageSelected(int arg0) {
                setImageBackground(arg0 % banners.size());
            }
        });
    }

    private void getViewpagerdate() {
        mImageViews = new ImageView[2][];
        // 将图片装载到数组中,其中一组类似缓冲，防止图片少时出现黑色图片，即显示不出来
        mImageViews[0] = new ImageView[banners.size()];
        mImageViews[1] = new ImageView[banners.size()];

        imageFlag = new ImageView[2];
        imageFlag[0] = new ImageView(mContext);
        imageFlag[1] = new ImageView(mContext);
        imageFlag[1].setBackgroundResource(R.mipmap.demo);

        imageFlag[0].setBackgroundResource(R.mipmap.demo);

        for (int i = 0; i < mImageViews.length; i++) {
            for (int j = 0; j < mImageViews[i].length; j++) {
                ImageView imageView = new ImageView(mContext);
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
//                ImageLoader.getInstance().displayImage(banners.get(0), imageView);
                ImageLoader.getInstance().displayImage(banners.get(j % banners.size()), imageView);

                //bitmapUtils.display(imageView, banners.get(j % banners.size()));
                //imageView.setBackgroundResource(imgIdArray[j]);
                mImageViews[i][j] = imageView;
            }
        }
        if (tips != null) {//有本地缓存数据时导致的，多出空白点隐藏掉
            for (int i = 0; i < tips.length; i++) {
                tips[i].setVisibility(View.GONE);
            }
        }
        tips = new ImageView[banners.size()];

        if (banners.size() <= 1)
            group.setVisibility(View.GONE);
        for (int i = 0; i < tips.length; i++) {
            ImageView imageView = new ImageView(mContext);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.setMargins(10, 10, 0, 0);
            imageView.setLayoutParams(lp);
            // imageView.setLayoutParams(new LayoutParams(20, 20));
            tips[i] = imageView;
            if (i == 0) {
                //   tips[i].setBackgroundResource(R.drawable.page_02);
                tips[i].setBackgroundResource(R.mipmap.page_flag_1);
            } else {
                tips[i].setBackgroundResource(R.mipmap.page_flag_2);
                //  tips[i].setBackgroundResource(R.drawable.page_01);
            }

            group.addView(imageView);
        }
    }

    /**
     * 设置选中的tip的背景
     *
     * @param selectItemsIndex
     */
    private void setImageBackground(int selectItemsIndex) {
        for (int i = 0; i < tips.length; i++) {
            if (i == selectItemsIndex) {
                tips[i].setBackgroundResource(R.mipmap.page_flag_1);
            } else {
                tips[i].setBackgroundResource(R.mipmap.page_flag_2);
            }
        }
    }


    public class MyAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return Integer.MAX_VALUE;
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            if (position == 0 || position == 1) {
                container.removeView(imageFlag[position]);
                return;
            }
            // Log.i("destroyItem", ""+position);
            if (banners.size() == 1)
                container.removeView(mImageViews[position
                        / banners.size() % 2][0]);
            else
                container.removeView(mImageViews[position
                        / banners.size() % 2][position % banners.size()]);
        }

        /**
         * 载入图片进去，用当前的position 除以 图片数组长度取余数是关键
         */
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            // Log.i("instantiateItem", ""+position);
            if (position == 0 || position == 1) {
                return imageFlag[position];
            }

/*
            ((BaseViewPager) container).removeAllViews();
*/
            if (banners.size() == 1) {
                container.addView(mImageViews[position
                        / banners.size() % 2][0]);
                return mImageViews[position / banners.size() % 2][0];
            } else {
             /*   bitmapUtils.display(mImageViews[position
                        / banners.size() % 2][position % banners.size()],banners.get(1));*/
                container.addView(mImageViews[position
                                / banners.size() % 2][position % banners.size()],
                        0);
            }
            return mImageViews[position / banners.size() % 2][position
                    % banners.size()];
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putString("id", productId);
        outState.putString("image_url", imageUrl);
        outState.putString("title", titleStr);
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (dialog != null) {
            dialog.onResult(requestCode, resultCode, data);
        }
    }

    ShareDialog dialog;

    private void share() {
        if (dialog == null)
            dialog = new ShareDialog(this);
//        SharedPreferences user = getSharedPreferences(
//                Constant.USERINFO, Activity.MODE_PRIVATE);
        String cityId = ApplicationHelper.getInstance().getCity().getCityId();
        String url = com.epfresh.api.constant.Constant.URL_SHARE_BASE + productId + "&" + cityId + "&" + promotionItemId + "&" + storeId;

        L.d("shareurl:", "share_url:" + "imageurl:" + imageUrl);
        L.d("shareurl:", "share_url:" + "description:" + description);
        L.d("shareurl:", "share_url:" + "titleStr:" + titleStr);
        L.d("shareurl:", "share_url:" + "productId:" + productId);
        if (imageUrl == null || "".equals(imageUrl)) {
            if (goodsDetail != null && goodsDetail.getImgList() != null && goodsDetail.getImgList().size() > 0) {
                String s = goodsDetail.getImgList().get(0);
                if (s == null) {
                    s = "";
                }
                imageUrl = s;
            } else {
                imageUrl = "";
            }
        }
        if (titleStr == null || "".equals(titleStr)) {
            titleStr = "e批生鲜";
        }
        if (description == null || "".equals(description)) {
            description = "推荐商品";
        }

        if (banners != null && banners.size() > 0) {
            imageUrl = banners.get(0);
        }
        if (imageUrl == null || "".equals(imageUrl)) {
            imageUrl = "http://m.epfresh.com/images/app-purlogo.png";
        }
        dialog.showDialog(url, imageUrl, description, titleStr, productId);

    }


    AddCartDialog addCartDialog;

    public void addCart() {

        if (goodsDetail == null) {
            return;
        }
        if (ApplicationHelper.getInstance().getUser().getAccess_token() == null || "".equals(ApplicationHelper.getInstance().getUser().getAccess_token())) {
            Intent intent = new Intent(this, LoginActivity.class);
            intent.putExtra("relogin", true);
            startActivity(intent);
            return;
        }
        if (addCartDialog == null) {
            addCartDialog = new AddCartDialog(this);
            addCartDialog.setOnAddCartListener(new AddCartDialog.OnAddCartListener() {
                @Override
                public void onAddCart(double cnt) {

                    if (goodsDetail.getProductParseDto().getType() == 2) {
                        //Intent main = new Intent(mContext, CartOrderActivity.class);
                        Intent main = new Intent(mContext, CartOrderNewActivity.class);


                        Map<String, Object> map = new HashMap<>();

                        map.put("productCount", cnt + "");

                        map.put("versionId", goodsDetail.getLastSnapshotId());
                        map.put("specId", productId);
                        map.put("salesType", "2");
                        map.put("specModefiedTime", goodsDetail.getModifiedTime());
                        map.put("productUnitPrice", goodsDetail.getPrice() + "");

                        main.putExtra("marketId", goodsDetail.getMarketId());
                        main.putExtra("preProduct", new Gson().toJson(map));

                        //订金
                        float deposit = goodsDetail.getDepositFloat();
//                        float total = cnt*goodsDetail.getPriceFloat();
//                        float secondPrice = total - deposit * cnt;

                        Map<String, StoreGoodsPrice> mapStorePrice = new HashMap<>();


                        String storeId = goodsDetail.getStoreId();

                        if (storeId != null && !"".equals(storeId)) {
                            StoreGoodsPrice storeGoodsPrice = mapStorePrice.get(storeId);
                            if (storeGoodsPrice == null) {
                                storeGoodsPrice = new StoreGoodsPrice();
                            }
                            //将同一商店的商品累加
//                            storeGoodsPrice.addSalePrice(total);
                            mapStorePrice.put(storeId, storeGoodsPrice);
                        }


                        main.putExtra("storePrice", new Gson().toJson(mapStorePrice));
                        startActivity(main);
                    } else {
                        requestAddCart(cnt);
                    }
                }
            });

            addCartDialog.setOnDismissListener(new BaseDialogView.OnDismissListener() {
                @Override
                public void onDismiss(Object o) {

                    View view = (getWindow()).peekDecorView();
                    if (view != null) {
                        InputMethodManager inputmanger = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                        inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
                    }
                }
            });
        }

        if (goodsDetail.isDc()) {

            addCartDialog.show(goodsDetail, addCartDialog.calMin(goodsDetail));
        } else {
            addCartDialog.show(goodsDetail, addCartDialog.calMin(goodsDetail));
        }
    }


    public void cart() {
        if (ApplicationHelper.getInstance().getUser().getAccess_token() == null || "".equals(ApplicationHelper.getInstance().getUser().getAccess_token())) {
            Intent intent = new Intent(this, LoginActivity.class);
            intent.putExtra("relogin", true);
            startActivity(intent);
            return;
        }

        Intent intent = new Intent(this, HomeActivity.class);
        intent.putExtra("home_tab_index", 1);
        startActivity(intent);
        finish();
    }

    public void rest() {
        toast(tvRest.getText().toString());
    }


    @Override
    public void onBackPressed() {
        if (addCartDialog != null && addCartDialog.isShowing()) {
            addCartDialog.dismiss();
        } else
            super.onBackPressed();
    }

    /* CartHelper cartHelper = new CartHelper();
     public void reqCartCnt(double productCount) {

         if (goods != null) {
             goods.setCount(productCount);
             adapterGoods.notifyDataSetChanged();
         }
         if (!cartHelper.checkIsCartRequesting(goods)){
             updateCartCnt(productCount,goods);
         }else {

         }
     }

     public void responseCartCnt(boolean isFail,ListGoods goods,double cnt){
         if (isFail){
             cartHelper.responseCartFail(goods);
         }else {
             cartHelper.responseCartSuccess(goods,cnt);
         }
     }*/
    public void requestAddCart(double cnt) {
        RequestEntityMap re = new RequestEntityMap();
        re.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_cart_add);//todo:2018年11月13日17:45:05
        if (goodsDetail.getPromotion() != null) {
            if (String.valueOf(goodsDetail.getPromotion().getItemId()) != null && !String.valueOf(goodsDetail.getPromotion().getItemId()).equals("")) {
                re.putParameter("specPromotionItemId", goodsDetail.getPromotion().getItemId());
            }
        }

//        re.putParameter("salesType", goodsDetail.getType());
//        re.putParameter("isAdd", 2);
        re.putParameter("count", cnt);
//        re.putParameter("specId", goodsDetail.getId());
        re.putParameter("specId", goodsDetail.getProductSpecPrice().getProductSpecId());
        if (serviceStoreId != -1) {
            re.putParameter("serviceStoreId", serviceStoreId);
        }
//        re.putParameter("productUnitPrice",goodsDetail.getPriceOnly());
//        re.putParameter("versionId", goodsDetail.getLastSnapshotId());
//        re.putParameter("cityId", ApplicationHelper.getInstance().getCity().getCityId());
//        re.putParameter("accountId", ApplicationHelper.getInstance().getUser().getAccountId());
        request(re, com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_order_cart_add, new OnRequestListener<AddCarResponse>() {
            @Override
            public AddCarResponse jsonToObj(String s) {
                return new Gson().fromJson(s, AddCarResponse.class);
            }

            @Override
            public void onFail(int i, Object o, Object o1) {
                hideProgressDialog();
            }

            @Override
            public void onResponseError(int i, Object o, Object o1) {
                hideProgressDialog();
            }

            @Override
            public void onStart(Object o) {
                showProgressDialog();
            }

            @Override
            public void onResponse(ResponseEntity<AddCarResponse> responseEntity, Object o) {
                hideProgressDialog();
                AddCarResponse responseElement = responseEntity.getResponseElement();
                if (responseElement != null) {
                    DataManager.getInstance().oftenListReFresh = true;
                    String id = responseElement.getShoppingCarId();
                    if (id != null && !"".equals(id)) {
                        addCartDialog.dismiss();
                        int shoppingCarCnt = responseElement.getshoppingCarCnt();
                        DataManager.getInstance().isNeedRefreshCart = true;

                        toast("添加购物车成功");
                        int cnt = 1;

//                    if (VerificationUtils.isNumeric(shoppingCarCnt)) {
//                        cnt = Integer.valueOf(shoppingCarCnt);
//                    }
//                        updateMsgCount(shoppingCarCnt);
//                        DataManager.getInstance().setCartCntStatus(shoppingCarCnt);
                        DataManager.getInstance().updateCartCnt();
                    }
                }

            }
        });


    }


    public void request() {
        if (goodsDetail != null) {
            RequestEntityMap re = new RequestEntityMap();
            re.setCmd(com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_store_store_dcStore);
            if (serviceStoreId != -1) {
                re.putParameter("storeId", serviceStoreId);
            } else {
                re.putParameter("storeId", goodsDetail.getStoreId());
            }
            request(re, com.epfresh.api.constant.AppPurchaseRouterConstant.cmd_store_store_dcStore, onDetailRequestListener);
        }
    }


    OnRequestListener<StoreDetail> onDetailRequestListener = new OnRequestListener<StoreDetail>() {
        @Override
        public StoreDetail jsonToObj(String s) {
            return new Gson().fromJson(s, StoreDetail.class);
        }

        @Override
        public void onFail(int i, Object o, Object o1) {
            hideProgressDialog();
        }

        @Override
        public void onResponseError(int i, Object o, Object o1) {
            hideProgressDialog();

        }

        @Override
        public void onStart(Object o) {
            showProgressDialog();
        }

        @Override
        public void onResponse(ResponseEntity<StoreDetail> responseEntity, Object o) {
            hideProgressDialog();
            StoreDetail responseElement = responseEntity.getResponseElement();

            if (responseElement != null) {

                if (!responseElement.isResult()) {
                    Intent tv_more = new Intent(DetailGoodsActivity.this,
                            CenterListActivity.class);
                    startActivity(tv_more);
                } else {
                    Intent tv_bulk_load = new Intent(DetailGoodsActivity.this,
                            DcStoreActivity.class);
                    tv_bulk_load.putExtra("data", new Gson().toJson(responseElement));
                    startActivity(tv_bulk_load);
                }
            } else {

            }

        }
    };

    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("DetailGoods"); //统计页面(仅有Activity的应用中SDK自动调用，不需要单独写。"SplashScreen"为页面名称，可自定义)
        MobclickAgent.onResume(this);          //统计时长
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("DetailGoods"); // （仅有Activity的应用中SDK自动调用，不需要单独写）保证 onPageEnd 在onPause 之前调用,因为 onPause 中会保存信息。"SplashScreen"为页面名称，可自定义
        MobclickAgent.onPause(this);
    }

    @Override
    public void onCountDownListener(boolean isFinish) {
        if (isFinish) {
            requestDetail();
        }
    }
}
